import { Component, OnInit, Output,EventEmitter } from '@angular/core';

@Component({
  selector: 'app-price-quote',
  templateUrl: './price-quote.component.html',
  styleUrls: ['./price-quote.component.css']
})
export class PriceQuoteComponent implements OnInit {

  StackCode:string = 'Apple';

  StackPrice:number = 100;

  @Output()
  lastprice:EventEmitter<PriceQuote> = new EventEmitter();

  @Output()
  buy:EventEmitter<PriceQuote> = new EventEmitter();
  constructor() {
    setInterval(() =>{
      let priceQuote:PriceQuote = new PriceQuote(this.StackCode,100*Math.random());
      this.StackPrice = priceQuote.lastprice;
      //将生成的这个值发送出去
      this.lastprice.emit(priceQuote);
    },1000);

  }

  ngOnInit() {
  }

  //定义函数
  buyStack(evnet){
    this.buy.emit(new PriceQuote(this.StackCode,this.StackPrice));
  }

}

export class PriceQuote{
  constructor(public stackcode:string,public lastprice:number){

  }
}
